import http from "@/common/http/index.js";

/*
 * 获取收藏数
 * topic_id:   主题ID, 如景区ID、文章ID
 * topic_type: 主题类型; 0: 景区, 1: 文章
 */
function getNum(topic_id, topic_type) {
  let params = { topic_id: topic_id, topic_type: parseInt(topic_type) };
  return http.get("/collect/num", params);
}

/*
 * 用户（当前登录用户）是否收藏
 * topic_id:   主题ID, 如景区ID、文章ID
 * topic_type: 主题类型; 0: 景区, 1: 文章
 */
function queryCollect(topic_id, topic_type) {
  let params = { topic_id: topic_id, topic_type: parseInt(topic_type) };
  return http.get("/collect", params);
}

/*
 * 切换用户收藏状态, 返回收藏数
 * topic_id:   主题ID, 如景区ID、文章ID
 * topic_type: 主题类型; 0: 景区, 1: 文章
 */
function changeCollect(topic_id, topic_type) {
  let params = { topic_id: topic_id, topic_type: parseInt(topic_type) };
  return http.post("/collect/change", params);
}

//获取用户收藏列表
//topic_type:主题类型; 0: 景区, 1: 文章
function getUserCollect(topic_type) {
  let params = { topic_type: parseInt(topic_type) };
  return http.post("/collect/get", params);
}

export default {
  getNum,
  queryCollect,
  changeCollect,
  getUserCollect
};
